﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace UI.Lib
{
    public class PsException : Exception
    {
        private int _errorNum = 0;

        public int ErrorNum
        {
            get { return _errorNum; }
            set { _errorNum = value; }
        }

        private string _errMsg = "";

        public string ErrMsg
        {
            get
            {
                string _emp = (!string.IsNullOrEmpty(_errMsg)) ? _errMsg : GetMsg();
                return string.Format("{0} | {1}", this.ErrorNum, _emp);
            }
        }

        public PsException(int num)
        {
            this._errorNum = num;
        }

        public PsException(int num, string msg)
        {
            this._errorNum = num;
            this._errMsg = msg;
        }

        public string GetMsg()
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(System.Windows.Forms.Application.StartupPath + "/drt.dat");
                XmlNode _node = xmldoc.SelectSingleNode("/Msgs/Msg[@id='" + this._errorNum + "']");
                return _node.InnerText;
            }
            catch (Exception e)
            {
                Components.LogHelper.Entity.Out("读取异常信息XML出错！\r\n" + e.Message);
                return "未知错误";
            }
        }
    }
}
